

#include "photosensitive_device.h"

static e_device_err cc_photosensitive_read_cb(void* user_data, const char* msg, int type,
                                              void* data)
{
  user_device_t dev = (user_device_t)user_data;
  if (dev == CC_NULL)
  {
    cc_log_e("device is null\r\n");
    return DEVICE_ENULL;
  }
  uint8_t* is_trigger = (uint8_t*)data;
  dev->num_data[0] = digitalRead(dev->pin[0]);
  *is_trigger = (uint8_t)dev->num_data[0];
  return DEVICE_EOK;
}
static e_device_err cc_photosensitive_write_cb(void* user_data, const char* msg, int type,
                                               void* data)
{
  user_device_t dev = (user_device_t)user_data;
  if (dev == CC_NULL)
  {
    cc_log_e("device is null\r\n");
    return DEVICE_ENULL;
  }

  cc_log_d("cc_photosensitive_write_cb\r\n");
  return DEVICE_EOK;
}
static e_device_err cc_photosensitive_control_cb(void* user_data, const char* msg, int type,
                                                 void* data)
{
  user_device_t dev = (user_device_t)user_data;
  if (dev == CC_NULL)
  {
    cc_log_e("device is null\r\n");
    return DEVICE_ENULL;
  }

  return DEVICE_EOK;
}

static e_device_err cc_photosensitive_control_exit_cb(void* user_data)
{
  cc_log_d("cc_photosensitive_control_exit_cb\r\n");
  return DEVICE_EOK;
}

static e_device_err cc_photosensitive_read_exit_cb(void* user_data)
{
  cc_log_d("cc_photosensitive_read_exit_cb\r\n");
  return DEVICE_EOK;
}

static e_device_err cc_photosensitive_write_exit_cb(void* user_data)
{
  cc_log_d("cc_photosensitive_write_exit_cb\r\n");
  return DEVICE_EOK;
}

e_device_err cc_photosensitive_init(void* device)
{
  user_device_t dev = (user_device_t)device;
  pinMode(dev->pin[0], INPUT);
  dev->control_cb = cc_photosensitive_control_cb;
  dev->read_cb = cc_photosensitive_read_cb;
  dev->write_cb = cc_photosensitive_write_cb;
  return DEVICE_EOK;
}
CC_DEVICE_INIT_MOUNT(cc_photosensitive_init, CC_DEVICE_TYPE_PHOTOSENSITIVE)
